import { showMsg, usersInvitationList } from '../../../vuex/action'

export default {
  name: 'Invitation',
  data() {
    return {
      searchType: 2,
      searchTxt: '',
      list: []
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xGetList: usersInvitationList
    }
  },
  methods: {
    search() {
      var searchTxt = this.searchTxt
      if (!searchTxt.length) {
        return this.xShowMsg({
          type: 'danger',
          content: '请输入后搜索'
        })
      }

      var searches = searchTxt.split(/[ ]*(?:，| |,)[ ]*/)
      var searchParams = {}
      searches = JSON.stringify(searches)
      switch (+this.searchType) {
        case 1:
          searchParams.phones = searches
          break
        case 2:
          searchParams.ids = searches
          break
        default:
      }

      this.xGetList(searchParams)
        .then((data) => {
          this.list = data
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
